package com.mxf.code.state_factory2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class StateController {
    
    @Autowired
    private StateFactory stateFactory;

    @GetMapping("/state")
    public String getState(@RequestParam("type") String type) {
        StateContext stateContext = new StateContext();
         
        State state = stateFactory.getState(type);
        state.doAction(stateContext);
         
        return "Current state: " + stateContext.getState().toString();
    }
}
